#!/bin/bash
branch=`git symbolic-ref --short -q HEAD`
commit=`git rev-parse HEAD`
commit=${commit:0:8}
time=$(date +%s)"000"
version=`cat $1 | grep 'version:' | sed -r 's/.*version:.*"(.*)(".*)/\1/g'`

echo Implementation-Version: $version > MANIFEST.MF
echo commit: $commit >> MANIFEST.MF
echo branch: $branch >> MANIFEST.MF
echo buildTime: $(date '+%y-%m-%d %H:%M:%S') >> MANIFEST.MF
mkdir -p dist
mv MANIFEST.MF dist/

version_rp="s/(version:\s*\").*(\")/\1"$version"\2/"
branch_rp="s#(branch:\s*\").*(\")#\1"$branch"\2#"
commit_rp="s/(commit:\s*\").*(\")/\1"$commit"\2/"
time_rp="s/(time:\s*\").*(\")/\1"$time"\2/g"
sed -i -r $branch_rp $1  
sed -i -r $commit_rp $1 
sed -i -r $time_rp $1
